// 计算最大间距
let arr = [3,6,9,1]
if(arr.length < 2){
  console.log(0)
} else {
  let max = 0
  let len = arr.length - 1
  let space
  for (let i=len, tmp; i > 0; i--) {
    for (let j = 0; j<i; j++) {
      if (arr[j] > arr[j+1]) {
        tmp = arr[j]
        arr[j] = arr[j+1]
        arr[j+1] = tmp
      }
    }
    if (i < len) {
      space = arr[i+1] - arr[i]
      if (space > max) {
        max = space
      }
    }
  }

  max = Math.max(max, arr[1] - arr[0])

  // arr.sort()
  // let max = 0
  // for(let i = 0, len=arr.length-1; i<len;i++){
  //   let val = arr[i+1] - arr[i]
  //   if(max < val){
  //     max = val 
  //   }
  // }
  console.log(max)
}